package com.xoa.service.workflow.reportSettings.impl;


import com.xoa.dao.department.DepartmentMapper;
import com.xoa.dao.reportSettings.FlowReportMapper;
import com.xoa.dao.users.UsersMapper;
import com.xoa.dao.workflow.FlowFormTypeMapper;
import com.xoa.dao.workflow.FlowReportPrivMapper;
import com.xoa.dao.workflow.FlowRunMapper;
import com.xoa.dao.workflow.FlowSortMapper;
import com.xoa.model.department.Department;
import com.xoa.model.users.Users;
import com.xoa.model.workflow.*;
import com.xoa.service.workflow.reportSettings.FlowReportService;
import com.xoa.util.ConvertMoney;
import com.xoa.util.PHPPherialize;
import com.xoa.util.ToJson;
import com.xoa.util.page.PageParams;
import de.ailis.pherialize.Pherialize;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.ss.util.CellRangeAddress;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.*;

@Service

public class FlowReportServiceImpl implements FlowReportService {
    //private static final String isNumber="[0-9]+";
    private static final String isNumber="^[0.0-9.0]+$";
    private int leftIndex=0;//运算符左侧坐标
    private int rightIndex=0;//运算符右侧坐标
    private final String cuowu="zzzzllllyyyywwwwyyyy";//数据非数字
    @Autowired
    private FlowSortMapper flowSortMapper;

    private String number="^[+-]?\\d+(\\.\\d+)?$";

    @Autowired
    private FlowFormTypeMapper flowFormTypeMapper;

    @Resource
    private FlowReportMapper flowReportMapper;

    @Resource
    FlowReportPrivMapper FlowReportPrivMapper;

    @Resource
    UsersMapper usersMapper;
    @Resource
    DepartmentMapper departmentMapper;
    @Resource
    private FlowRunMapper flowRunMapper;


    //报表设置查询
    @Override
    public ToJson<FlowReport> queryReportSettings(String flowId, String rName, Integer page, Integer pageSize, Boolean useFlag) {
        ToJson<FlowReport> json = new ToJson<FlowReport>();
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("flowId", flowId);
            map.put("rName", rName);
            PageParams pageParams = new PageParams();
            pageParams.setPage(page);
            pageParams.setPageSize(pageSize);
            pageParams.setUseFlag(true);
            map.put("page", pageParams);
            List<FlowReport> list = flowReportMapper.queryReportSettings(map);
            for (FlowReport flowReport : list) {
                if (flowReport.getCreateDate().length() > 18) {
                    String date = flowReport.getCreateDate();
                    date = date.substring(0, date.length() - 2);
                    flowReport.setCreateDate(date);
                }
            }
            if (list.size() > 0) {
                json.setObj(list);
                json.setTotleNum(pageParams.getTotal());
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {

            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;

    }

    //报表设置删除
    @Override
    public ToJson<FlowReport> deleteReportSettings(Integer rId) {
        ToJson<FlowReport> json = new ToJson<FlowReport>(1, "err");
        try {
            int count = flowReportMapper.deleteReportSettings(rId);
            if (count > 0) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }


    //根据flowId查询表单名称
    @Override
    public ToJson<FlowFormType> querybyFlowIdField(String flowId) {
        ToJson<FlowFormType> json = new ToJson<FlowFormType>(1, "err");
        try {
            List<FlowFormType> list = flowReportMapper.querybyFlowIdField(flowId);
            if (list.size() > 0) {
                json.setObj(list);
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    //按照用户与部门及报表Id新建权限
    @Override
    public ToJson<FlowReportPriv> newReportPermission(String rId, String userStr, String deptStr) {
        ToJson<FlowReportPriv> json = new ToJson<FlowReportPriv>(1, "err");
        try {
            Map<String,Object>map = new HashMap<String,Object>();
            map.put("rId",rId);
            map.put("userStr",userStr);
            map.put("deptStr",deptStr);
            int count = FlowReportPrivMapper.insertReportPermission(map);
            if (count > 0) {
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public ToJson<FlowReportPriv> updateReportPermission(String rId,String pId, String userStr, String deptStr) {
        ToJson<FlowReportPriv> json = new ToJson<FlowReportPriv>(1, "err");
        try {
            Map<String,Object>map = new HashMap<String,Object>();
            map.put("rId",rId);
            map.put("pId",pId);
            map.put("userStr",userStr);
            map.put("deptStr",deptStr);
            int count = FlowReportPrivMapper.updateReportPermission(map);
            if (count > 0) {
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public ToJson<FlowReportPriv> deleteReportPermission(String id, String rId) {
        ToJson<FlowReportPriv> json = new ToJson<FlowReportPriv>(1, "err");
        try {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("id", id);
            map.put("rId", rId);
            int count = FlowReportPrivMapper.deleteReportPermission(map);
            if (count > 0) {
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public ToJson<FlowReportPriv> queryReportPermission(String rId) {
        ToJson<FlowReportPriv> json = new ToJson<FlowReportPriv>(1, "err");
        try {
            List<FlowReportPriv> list = new ArrayList<FlowReportPriv>();
            list = FlowReportPrivMapper.queryReportPermission(rId);
            if (list.size() > 0) {
                //用户Id查询相应名字，返回给前台
                for(FlowReportPriv flowReportPriv:list){
                    String userS = "";
                    String userIdStr =  flowReportPriv.getUserStr();
                    if(userIdStr.length()>0){
                        //获取用户字符串，按，分割
                        String[] userStr = userIdStr.split(",");
                        int j = 0;
                        for(int i =0;i<userStr.length;i++){
                            //根据分割的用户ID查出用户名称
                            String username = usersMapper.getUsernameByUserId(userStr[i]);
                            if(j==0){
                                userS +=username;
                                j = j+1;
                            }else{
                                userS +=","+username;
                            }
                        }
                        //返给前端
                        flowReportPriv.setUserStr(userS);
                    }
                    //做部门名称显示处理
                    switch (flowReportPriv.getDeptStr()){
                        case "ALLDEPT":
                            break;
                        case "DEPT":
                            break;
                        default:
                            String deptStr = flowReportPriv.getDeptStr();
                            String deptS = "";
                            String[] deptStrArray = deptStr.split(",");
                            for(int i =0;i<deptStrArray.length;i++){
                                Department department = departmentMapper.getDeptById(Integer.valueOf(deptStrArray[i]));
                                if(i==0){
                                    deptS+= department.getDeptName();
                                }else{
                                    deptS+=","+department.getDeptName();
                                }
                            }
                            flowReportPriv.setDeptStr(deptS);
                    }
                }
                json.setObj(list);
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {

            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }
    @Override
    public ToJson<FlowReportPriv> selectReportPermission(String rId, String id) {
        ToJson<FlowReportPriv> json = new ToJson<FlowReportPriv>(1, "err");
        try {
            List<FlowReportPriv> list = new ArrayList<FlowReportPriv>();
            Map<String,Object> map = new HashMap<String,Object>();
            map.put("rId",rId);
            map.put("pId",id);
            list = FlowReportPrivMapper.selectReportPermission(map);
            if (list.size() > 0) {
                for(FlowReportPriv flowReportPriv:list){
                    String userS = "";
                    String userIdStr =  flowReportPriv.getUserStr();
                    if(userIdStr.length()>0){
                        String[] userStr = userIdStr.split(",");
                        int j = 0;
                        for(int i =0;i<userStr.length;i++){
                            String username = usersMapper.getUsernameByUserId(userStr[i]);
                            if(j==0){
                                userS +=userStr[i]+":"+username;
                                j = j+1;
                            }else{
                                userS +=","+userStr[i]+":"+username;
                            }
                        }
                        flowReportPriv.setUserStr(userS);
                    }

                    //获取部门字符串按，分割
                    String deptStr = flowReportPriv.getDeptStr();
                    String deptS = "";
                    if(deptStr.length()>0) {
                        switch (deptStr) {
                            case "ALLDEPT":
                                break;
                            case "DEPT":
                                break;
                            default:
                                String[] dStr = deptStr.split(",");
                                int k = 0;
                                for (int i = 0; i < dStr.length; i++) {
                                    //根据分割的用户ID查出用户名称
                                    String deptname = departmentMapper.getDeptNameById(Integer.valueOf(dStr[i]));
                                    if (k == 0) {
                                        deptS += dStr[i] + ":" + deptname;
                                        k = k + 1;
                                    } else {
                                        deptS += "," + dStr[i] + ":" + deptname;
                                    }
                                }
                                //返给前端
                                flowReportPriv.setDeptStr(deptS);
                                break;
                        }

                    }
                }
                json.setObj(list);
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }
    //新建报表设置
    @Override
    public ToJson<FlowReport> newReportSettings(Integer tid, String flowId, String rName,String[] listItem, String[] queryItem,
                                                String createUser, String groupType, String groupField,String formId) {
        ToJson<FlowReport> json = new ToJson<FlowReport>(1, "err");
        try {
            Map<String,Object>map = new HashMap<String,Object>();

            List Itemlist = new ArrayList();//listItem字段转化
            List queryItemList = new ArrayList();
            List<Map<String,Object>> list1 = new ArrayList<Map<String,Object>>();
            Map<String,Object>itemMap = new HashMap<String,Object>();
            Map<String,Object>queryMap = new HashMap<String,Object>();
            //定义字符串循环遍历数组
            String item = null;
            String query = null;
            String query1=null;
            //"{field=DATA_8, disp_name:费用预计, calc_type:0, formulate:, weight:}
            if(listItem.length>0){
                for(int i =0;i<listItem.length;i++){
                    if(!"".equals(listItem[i])){
                        String[] itemArray = listItem[i].split(",");
                        for(int j =0;j<itemArray.length;j++){
                            item = itemArray[j];
                            itemMap.put(item.substring(0,item.indexOf("=")), item.substring(item.indexOf("=")+1,item.length()));
                        }
                        Itemlist.add(itemMap);
                        itemMap = new HashMap<>();
                    }
                }
            }
            if(queryItem.length>0){
                for(int i =0;i<queryItem.length;i++){
                    if(!"".equals(queryItem[i])){
                        String[] queryArray = queryItem[i].split(",");
                        for(int j =0;j<queryArray.length;j++){
                            query = queryArray[j];
                            String[] queryl = query.split(",");
                            for(int z = 0;z<queryl.length;z++){
                                query1 = queryl[z];
                                queryMap.put(query1.substring(0,query.indexOf("=")), query1.substring(query1.indexOf("=")+1,query1.length()));
                            }
                        }
                        queryItemList.add(queryMap);
                        queryMap = new HashMap<>();
                    }

                }
            }
            Date date = new Date();
            SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String createDate = aDate.format(date);
            //序列化与21数据库一样的数据格式
            String ListItemStr = Pherialize.serialize(Itemlist);
            String QueryItemStr = Pherialize.serialize(queryItemList);
            if(tid==null){
                tid =0;
            }
            map.put("tId",tid);
            map.put("flowId",flowId);
            map.put("rName",rName);
            map.put("createUser",createUser);
            map.put("groupType",groupType);
            map.put("groupField",groupField);
            map.put("listItem",ListItemStr);
            map.put("queryItem",QueryItemStr);
            map.put("createDate",createDate);
            map.put("formId",formId);
            int count = flowReportMapper.newReportSettings(map);
            if(count>0){
                json.setMsg("success");
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }

    @Override
    public ToJson<FlowReport> queryIdReportSettings(Integer rId) {
        ToJson<FlowReport> json = new ToJson<FlowReport>(1, "err");
        try {
            Map<String,Object>map = new HashMap<String,Object>();
            map.put("rId",rId);
            List<FlowReport>flowReportList = flowReportMapper.queryIdReportSettings(map);
            for(FlowReport flowReport : flowReportList){
                String date = flowReport.getCreateDate();
                date = date.substring(0,date.length()-2);
                flowReport.setCreateDate(date);
                List listItem = PHPPherialize.getListByData(flowReport.getListItem());
                String strItem = "";
                String queryItemStr = "";
                for(int i =0;i<listItem.size();i++){
                    if(i==0){
                        strItem+= listItem.get(i)+"|";
                    }else{
                        strItem+= "{"+listItem.get(i)+"|";
                    }
                }
                String listItemStr = strItem.replace("=",":");
                flowReport.setListItem(listItemStr);
                List queryItem = PHPPherialize.getListByData(flowReport.getQueryItem());
                for(int i =0;i<queryItem.size();i++){
                    if(i==0){
                        queryItemStr+= queryItem.get(i)+"|";
                    }else{
                        queryItemStr+= queryItem.get(i)+"|";
                    }
                }
                String queryItemS = queryItemStr.replace("=",":");
                flowReport.setQueryItem(queryItemS);
            }
            if(flowReportList.size()>0){
                json.setMsg("success");
                json.setObj(flowReportList);
                json.setFlag(0);
            }
        } catch (Exception e) {
            json.setFlag(1);
            json.setMsg(e.getMessage());
            e.printStackTrace();
        }
        return json;
    }
    /**
     * 李然
     * @param userId
     * @return 返回此用户管理的报表数据
     */
    @Override
    public ToJson<FlowSort> getReportList(String userId) {
        ToJson<FlowSort> toJson=new ToJson<>();
        try {
            List<FlowReport> flowReportList=flowReportMapper.getReportListByUserId(userId);
            if(flowReportList.size()>0){
                List<Integer> flowIdList=new ArrayList<>();
                for(int i=0;i<flowReportList.size();i++){
                    flowIdList.add(flowReportList.get(i).getFlowId());
                }
                if(flowIdList.size()>0){
                    List<FlowSort> flowSortList=flowSortMapper.getFlowSortByFlowIdList(flowIdList);
                    List<FlowSort> flowSorts=new ArrayList<>();
                    if(flowSortList.size()>0){
                        for(int i=0;i<flowSortList.size();i++){
                            List<FlowReport> flowReports=new ArrayList<>();
                            FlowSort flowSort=flowSortList.get(i);
                            for(int j=0;j<flowReportList.size();j++){
                                if(flowSortList.get(i).getSortId()==flowReportList.get(j).getFlowSort()){
                                    flowReports.add(flowReportList.get(j));
                                }
                            }
                            flowSort.setFlowReportList(flowReports);
                            flowSorts.add(flowSort);
                        }
                    }
                    toJson.setObj(flowSorts);
                    toJson.setMsg("ok");
                    toJson.setFlag(0);
                }
            }else{
                toJson.setMsg("没有数据");
                toJson.setFlag(1);
            }
        } catch (Exception e) {
            toJson.setMsg( e.getMessage());
            toJson.setFlag(1);
            e.printStackTrace();
        }

        return toJson;
    }

    /**
     * 根据rid主键获取一条报表记录
     * @param rid
     * @return
     */
    @Override
    public ToJson<FlowReport> getReportById(Integer rid) {
        ToJson<FlowReport> toJson=new ToJson<>();
        try {
            FlowReport flowReport=flowReportMapper.getReportById(rid);
            if(flowReport!=null){
                List list=PHPPherialize.getListByData(flowReport.getQueryItem());
                List<FlowReportResult> flowReportResultList=new ArrayList<>();
                for(int i=0;i<list.size();i++){
                    String[] dataArray=list.get(i).toString().split(",");
                    FlowReportResult flowReportResult=new FlowReportResult();
                    for(int j=0;j<dataArray.length;j++){
                        String key=dataArray[j].substring(0,dataArray[j].indexOf("="));
                        key=key.trim();
                        String value=dataArray[j].substring(dataArray[j].indexOf("=")+1,dataArray[j].length());
                        value=value.trim();
                        if(key.equals("field")){
                            flowReportResult.setField(value);
                        }
                        if(key.equals("disp_name")){
                            flowReportResult.setDisp_name(value);
                        }
                    }
                    flowReportResultList.add(flowReportResult);
                }
                flowReport.setFlowReportResultList(flowReportResultList);
                if(flowReport!=null){
                    toJson.setObject(flowReport);
                    toJson.setMsg("ok");
                    toJson.setFlag(0);
                }else{
                    toJson.setMsg("没有数据");
                    toJson.setFlag(1);
                }
            }else{
                toJson.setMsg("没有数据");
                toJson.setFlag(1);
            }
        } catch (Exception e) {
            toJson.setMsg("getReportById代码出错");
            toJson.setFlag(1);
            e.printStackTrace();
        }

        return toJson;
    }

    /**lr
     * 通过查询条件查询
     * @param flowId
     * @param beginTime
     * @param endTime
     * @param deptIds
     * @param rid
     * @param definds
     * @return
     */
    @Override
    public ToJson queryReport(String flowId,String beginTime, String endTime, String deptIds, String userPrivs, Integer rid, String definds,Integer type,HttpServletResponse response) {
        ToJson toJson=new ToJson();

        String tableName= null;
        try {
            tableName = " flow_data_"+flowId;

            //用来拼接sql
            StringBuffer sb=new StringBuffer();
            Map<String,Object> maps=new HashMap();
            //根据rid取出数据库的表单字段，用于查询多表数据的头部信息（select xx,yy,cc from.....）
            FlowReport flowReport=flowReportMapper.getReportById(rid);
            String selectSql=null;
            Map map=null;
            if(flowReport!=null) {
                String listItem = flowReport.getListItem();
                map = PHPPherialize.getTitleSql(listItem);
                List<FlowReportResult> reportResultList=new ArrayList<>();
                //获取头部sql
                String titleSql = (String) map.get("selectSql");
                if(titleSql.charAt(0)==','){
                    titleSql=titleSql.substring(1,titleSql.length());
                }
                StringBuffer titleSqlSb=new StringBuffer();
                if(titleSql.contains(flowReport.getGroupField())&& titleSql.contains(",")){
                    String[] titleSqlArray=titleSql.split(",");
                    for(int i=0;i<titleSqlArray.length;i++){
                            if (!titleSqlArray[i].equals(flowReport.getGroupField())) {
                                titleSqlSb.append(titleSqlArray[i] + ",");
                                reportResultList.add((FlowReportResult) ((List)map.get("flowReportResultList")).get(i));
                            }
                    }
                }
                if(titleSqlSb.length()>0){
                    titleSql=titleSqlSb.toString();
                    map.put("flowReportResultList",reportResultList);
                }

                //拼接分组字段
                if(titleSql.charAt(0)!=',') {
                    selectSql = flowReport.getGroupField() +"," +titleSql;
                }else{
                    selectSql = flowReport.getGroupField() +titleSql;
                }

                if(selectSql.charAt(0)==','){
                    selectSql=selectSql.substring(1,selectSql.length());
                }
                    String[] selectSqlArray=selectSql.split(",");
                    StringBuffer sbSelect=new StringBuffer();
                    for(int i=0;i<selectSqlArray.length;i++){
                        sbSelect.append("a."+selectSqlArray[i]+",");
                    }
                    if(sbSelect.length()>0&& sbSelect.charAt(sbSelect.length()-1)==','){
                        selectSql=sbSelect.substring(0,sbSelect.length()-1);
                    }else{
                        selectSql=sbSelect.toString();
                    }

            }
            //解析自定义查询串，先通过||转出多组查询条件装配到defind数组中{xxx|s,d,f,g,}
            List<String> defind=new ArrayList();
            if(definds!=null && !definds.equals("")&&definds.length()>0){
                String[] defindArray=definds.split("\\|\\|");
                for(int i=0;i<defindArray.length;i++){
                    defind.add(defindArray[i]);
                }
            }
            //循环对每一组条件进行操作
            if(defind!=null&&defind.size()>0){
                for(int i=0;i<defind.size();i++){
                    //在通过|获得键和值{xxx :  s,d,f,g}
                    String[] keyValues = defind.get(i).split("\\|");
                    if((keyValues[0]!=null && !keyValues[0].equals(""))
                            && (keyValues[1]!=null && !keyValues[1].equals(""))){
                        //拼接sql的where条件
                        if(keyValues[1].charAt(keyValues[1].length()-1)==','){
                            keyValues[1]=keyValues[1].substring(0,keyValues[1].length()-1);
                        }
                        sb.append( " and a."+keyValues[0]+" in "+"("+"'"+keyValues[1]+"'"+")");
                    }
                }
            }
            String defindSql=null;
            if(sb!=null && sb.length()>0){
                defindSql=sb.toString();
            }
            if(!com.xoa.util.common.StringUtils.checkNull(userPrivs)){
                Set<Integer> deptSet = new HashSet<Integer>();
                List<Users> usersByPrivIds = usersMapper.getUsersByPrivIds(userPrivs.split(","));
                // 存储部门id
                for (int i=0,size=usersByPrivIds.size();i<size;i++) {
                    deptSet.add(usersByPrivIds.get(i).getDeptId());
                }
                // 拼接部门id
                StringBuilder deptIdsStr = new StringBuilder();
                Iterator<Integer> iterator = deptSet.iterator();
                while (iterator.hasNext()){
                    deptIdsStr.append(iterator.next()).append(",");
                }
                if(com.xoa.util.common.StringUtils.checkNull(deptIds)){
                    deptIds = deptIdsStr.toString();
                } else {
                    if(deptIds.charAt(deptIds.length()-1)==','){
                        deptIds = deptIds + deptIdsStr.toString();
                    } else {
                        deptIds = definds + "," + deptIdsStr.toString();
                    }
                }
            }
            if(deptIds!=null && deptIds.equals("")){
                deptIds=null;
            }else{
                if(deptIds.charAt(deptIds.length()-1)==','){
                    deptIds=deptIds.substring(0,deptIds.length()-1);
                }
            }

            if(beginTime!=null && !beginTime.equals("")){
                beginTime="'"+beginTime+"'";
            }else{
                beginTime=null;
            }

            if(endTime!=null && !endTime.equals("")){
                endTime="'"+endTime+"'";
            }else{
                endTime=null;
            }
            maps.put("tableName",tableName);
            maps.put("beginTime",beginTime);
            maps.put("endTime",endTime);
            maps.put("deptIds",deptIds);
            maps.put("defindSql",defindSql);
            maps.put("selectSql",selectSql);
            maps.put("rid",rid);
            List<FlowReportResult> list=getBodyList(maps,map,flowReport);
            List<List> listMain=grouping(list,flowReport);

            toJson.setMsg("lalalalal");
            if(type!=null&&type==1) {
                exportFlowReportExcel(listMain, response);
            }

            else {
                toJson.setFlag(0);
                toJson.setObj(listMain);
            }
       } catch (Exception e) {
            toJson.setMsg(e.getMessage());
            toJson.setFlag(1);
        }
        return toJson;
    }
    //获取展示的体部
    public List getBodyList(Map maps, Map map, FlowReport flowReport) {
        List<Map<String, Object>> listMapDb = this.flowReportMapper.queryReport(maps);
        List<FlowReportResult> flowReportResultList = (List)map.get("flowReportResultList");
        FlowReportResult flowReportResult = new FlowReportResult();
        List<String> listTitle = new ArrayList();
        String noNumber = "!";
        for(int j = 0; j < listMapDb.size(); ++j) {
            listTitle.add(((Map)listMapDb.get(j)).get(flowReport.getGroupField()) + "");
        }
        flowReportResult.setList(listTitle);
        Document document = this.getField(flowReport);
        String dispName = null;
        if (flowReport.getGroupField().equals("run_id") && !flowReport.getGroupField().equals("RUN_ID")) {
            dispName = "流水号";
        } else {
            dispName = this.getCustomTitle(document, flowReport.getGroupField());
        }

        if (dispName == null) {
            dispName = "组名(未查到组名)";
        }

        flowReportResult.setDisp_name(dispName);
        int i;
        ArrayList list;
        int j;
        if (flowReport.getGroupType().equals("1")) {
            for(i = 0; i < flowReportResultList.size(); ++i) {
                list = new ArrayList();

                for(j = 0; j < listMapDb.size(); ++j) {
                    list.add(((Map)listMapDb.get(j)).get(((FlowReportResult)flowReportResultList.get(i)).getField()) + "");
                }

                ((FlowReportResult)flowReportResultList.get(i)).setList(list);
            }
        } else {
            if (listTitle != null && listTitle.size() > 0) {
                listTitle.add("总结：");
            }
            for(i = 0; i < flowReportResultList.size(); ++i) {
                list = new ArrayList();
                String value;
                if (((FlowReportResult)flowReportResultList.get(i)).getCalc_type().equals("3")) {
                    for(j = 0; j < listMapDb.size(); ++j) {
                        value = (((Map)listMapDb.get(j)).get(((FlowReportResult)flowReportResultList.get(i)).getField()) + "").trim();
                        if (value != null && value.length() > 0) {
                            if (!value.matches("^[0.0-9.0]+$")) {
                                list.add(noNumber);
                            } else {
                                String formula = ((FlowReportResult)flowReportResultList.get(i)).getFormulate();
                                String formulaNumber = null;
                                formulaNumber = this.convertStr(formula, flowReport, maps, j);
                                if (formulaNumber != null) {
                                    String formulaWipeOff = this.resultBracket(formulaNumber);
                                    String result = this.operation(formulaWipeOff);
                                    list.add(result);
                                } else {
                                    list.add(noNumber);
                                }
                            }
                        } else {
                            list.add("");
                        }
                    }
                } else {
                    for(j = 0; j < listMapDb.size(); ++j) {
                        value = (((Map)listMapDb.get(j)).get(((FlowReportResult)flowReportResultList.get(i)).getField()) + "").trim();
                        if (value != null && value.length() > 0) {
                                list.add(value);
                        } else {
                            list.add("");
                        }
                    }
                }

                if (list.size() > 0) {
                    Double result = this.getResultStr2(list, (FlowReportResult)flowReportResultList.get(i), maps);
                    if(result==null){
                        list.add("");
                    }else {
                        list.add(result);
                    }
                }

                ((FlowReportResult)flowReportResultList.get(i)).setList(list);
            }
        }

        flowReportResultList.add(0, flowReportResult);
        return flowReportResultList;
    }
    private Double getResultStr2(List<String> valueList,FlowReportResult flowReportResult,Map<String,Object> maps){
        double result2=0.00;
        double count=0.00;
        double weightValue=0;
        double resultWeight=0.00;
        boolean flag=true;
        List<Double> integerList=new ArrayList<>();
        if(valueList.size()>0){
            List<String> valueRemove=new ArrayList<>();
            for(int i=0;i<valueList.size();i++){
                if(!valueList.get(i).equals("")){
                    valueRemove.add(valueList.get(i));
                }
            }
            if(valueRemove.size()>0) {
                valueList = valueRemove;
            }
            for (int i=0;i<valueList.size();i++){
                if(valueList.get(i).matches(number)==false){
                    flag=false;
                    integerList.clear();
                    break;
                }
                integerList.add(Double.valueOf(valueList.get(i)));
            }
        }
        if(flowReportResult.getCalc_type()!=null && !flowReportResult.getCalc_type().equals("")){
            if(flag==true) {
                switch (flowReportResult.getCalc_type()) {
                    case "0":
                        for (int i = 0; i < integerList.size(); i++) {
                            count = count + integerList.get(i);
                        }
                        result2 = count;
                        break;
                    case "1":
                        if (flowReportResult.getWeight() != null && !flowReportResult.getWeight().equals("")) {
                            maps.put("weight", flowReportResult.getWeight());
                            List<Integer> weightList = flowReportMapper.getweight(maps);
                            if (weightList.size() > 0) {
                                for (int i = 0; i < integerList.size(); i++) {
                                    count = count + (integerList.get(i) * weightList.get(i));
                                    weightValue = weightValue + weightList.get(i);
                                }
                                resultWeight = count / weightValue;
                                result2 = resultWeight ;
                            }

                        }
                        break;
                    case "2":
                        for (int i = 0; i < integerList.size(); i++) {
                            count = count + integerList.get(i);
                        }
                        if (integerList.size() > 0) {
                            count = count / integerList.size();
                            result2 = count ;
                        }
                        ;
                        break;
                    case "3":
                        for (int i = 0; i < integerList.size(); i++) {
                            count = count + integerList.get(i);
                        }
                        result2 = count ;
                        break;
                }
            }
        }
        if(result2==0.00){
            return null;
        }
        BigDecimal b = new BigDecimal(result2);
        double df = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return df;
    }
    //导出
    private void exportFlowReportExcel(List<List> excelList, HttpServletResponse response){
        List<String> titleList=excelList.get(0);
        List<FlowReportResult> bodyList=excelList.get(1);
        int col=0;//列
        int count=0;//行数
        int rowStatrtIndex=0;//合并单元格起始索引
        int rowEndIndex=0;//合并单元格终止索引
        try {
            // 获取当前时间
            Calendar c = Calendar.getInstance();
            String time =  ""+c.get(Calendar.YEAR) + (c.get(Calendar.MONTH) + 1)
                    + c.get(Calendar.DAY_OF_MONTH) + c.get(Calendar.HOUR_OF_DAY)
                    + c.get(Calendar.MINUTE);
            StringBuffer stringBuffer = new StringBuffer();
            HSSFWorkbook wb = new HSSFWorkbook();
            // 第二步，在webbook中添加一个sheet,对应Excel文件中的sheet
            HSSFSheet sheet = wb.createSheet("工作流数据报表信息");

            // 第四步，创建单元格，并设置值表头 设置表头居中
            HSSFFont font = wb.createFont();
            font.setFontHeightInPoints((short) 12); // 字体高度
            font.setColor(HSSFFont.COLOR_NORMAL); // 字体颜色
            font.setFontName("宋体"); // 字体
            font.setBold(true); // 宽度
            font.setItalic(false); // 是否使用斜体
            HSSFCellStyle style = wb.createCellStyle();
            style.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
            style.setFont(font);
            HSSFRow row = sheet.createRow((int) 0);
            HSSFFont font1 = wb.createFont();
            font1.setFontHeightInPoints((short) 12); // 字体高度
            font1.setColor(HSSFFont.COLOR_NORMAL); // 字体颜色
            font1.setFontName("宋体"); // 字体
            font1.setBold(true); // 宽度
            font1.setItalic(false); // 是否使用斜体
            HSSFCellStyle style1 = wb.createCellStyle();
            style1.setAlignment(HorizontalAlignment.CENTER); // 创建一个居中格式
            style1.setVerticalAlignment(VerticalAlignment.CENTER);
            style1.setFont(font1);
            for (int i = 0; i < titleList.size(); i++) {
                HSSFCell cell = row.createCell((short) i);
                cell.setCellValue(titleList.get(i));
                cell.setCellStyle(style);

            }

            if(bodyList!=null && bodyList.size()>0){
                for(int i=0;i<bodyList.size();i++){
                    for(int j=0;j<bodyList.get(i).getDispList().size();j++){
                        List<String> rowList=new ArrayList<>();
                        count++;
                        HSSFRow r=sheet.createRow(count);
                        rowList.add(bodyList.get(i).getDisp_name());
                        if(bodyList.get(i).getDispCount()!=null&&bodyList.get(i).getDispCount()>0){
                            rowList.add(bodyList.get(i).getDispCount()+"");
                        }
                        for(int n=0;n<bodyList.get(i).getDispList().get(j).size();n++){
                            rowList.add(bodyList.get(i).getDispList().get(j).get(n)+"");
                        }
                        for(int b=0;b<rowList.size();b++){
                            HSSFCell cell2=r.createCell(col);
                            cell2.setCellValue(String.valueOf(rowList.get(b)));
                            cell2.setCellStyle(style1);
                            col++;
                        }
                        col=0;
                    }
                    //合并单元格
                    if(bodyList.get(i).getDispList().size()>1){
                        sheet.addMergedRegion(new CellRangeAddress((count+1-bodyList.get(i).getDispList().size()), count, 0, 0));
                        if(bodyList.get(i).getDispCount()!=null &&bodyList.get(i).getDispCount()>1 ) {
                            sheet.addMergedRegion(new CellRangeAddress((count + 1 - bodyList.get(i).getDispList().size()), count, 1, 1));
                        }
                    }
                }

            }
            stringBuffer.append("工作流数据报表").append(time.toString()).append(".xls");

            // 设置每一列的宽度
            sheet.setDefaultColumnWidth(15);
            String fileName = stringBuffer.toString();
            response.setHeader("Content-disposition", "attachment;filename="
                    + URLEncoder.encode(fileName, "UTF-8"));
            response.setContentType("application/msexcel;charset=UTF-8");
            OutputStream out = response.getOutputStream();
            wb.write(out);
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    /**
     * @创建作者:李然  Lr
     * @方法描述：得到括号里的数值
     * @创建时间：10:03 2018/8/8

     **/
    public String resultBracket(String str1){
        StringBuilder str=new StringBuilder(str1);
        int leftBracket=0;
        int rightBracket=0;
        for(int i=0;i<str.length();i++){
            if(str.charAt(i)=='('){
                leftBracket=i;
            }
            if(str.charAt(i)==')'){
                rightBracket=i;
                String a=str.substring(leftBracket+1,rightBracket);
                String b=operation(a);
                str.replace(leftBracket,rightBracket+1,b);
                i=-1;
            }
        }
        return str.toString();
    }

    /**
     * @创建作者:李然  Lr
     * @方法描述：运算主方法
     * @创建时间：10:03 2018/8/8

     **/
    public String operation(String str1){
        StringBuilder str=new StringBuilder(str1);
        int symbolIndex=0;//运算符坐标
        if(str1.contains("*")||str1.contains("/")){
            for(int i=0;i<str.length();i++){
                if(str.charAt(i)=='*'|| str.charAt(i)=='/'){
                    symbolIndex=i;
                    String leftStr=leftString(str,symbolIndex);
                    String rightStr=rightString(str,symbolIndex);
                    String value=operationSwitch(leftStr,rightStr,str.charAt(symbolIndex));
                    str.replace(leftIndex,rightIndex,value);
                    str1=str.toString();
                    i=-1;
                }

            }

        }
        for(int j=0;j<str.length();j++){
            if(str.charAt(j)=='+'|| str.charAt(j)=='-'){
                if(j!=0) {
                    symbolIndex = j;
                    String leftStr = leftString(str, symbolIndex);
                    String rightStr = rightString(str, symbolIndex);
                    String value = operationSwitch(leftStr, rightStr, str.charAt(symbolIndex));
                    str.replace(leftIndex, rightIndex, value);
                    str1 = str.toString();
                    j = -1;
                }
            }
        }
        return str.toString();
    }

    /**
     * @创建作者:李然  Lr
     * @方法描述：获取左侧参数
     * @创建时间：10:02 2018/8/8

     **/
    public String leftString(StringBuilder str,Integer i){
        int stateIndex=0;//起始坐标
        int endIndex=0;//终止坐标
        for(int a=i-1;a>=0;a--){
            if(str.charAt(a)=='+'||str.charAt(a)=='-'||str.charAt(a)=='*'||str.charAt(a)=='/'||a==0) {
                if(a==0){
                    stateIndex=a;
                    endIndex=i;
                    break;
                }else{
                    if(str.charAt(a)=='-'&& (str.charAt(a-1)=='+'||str.charAt(a-1)=='-'||
                            str.charAt(a-1)=='*'||str.charAt(a-1)=='/')){
                        stateIndex=a;
                        endIndex=i;
                        break;
                    }
                    stateIndex=a+1;
                    endIndex=i;
                    break;
                }
            }
        }
        leftIndex=stateIndex;
        return str.substring(stateIndex,endIndex);
    }
    /**
     * @创建作者:李然  Lr
     * @方法描述：获取右侧参数
     * @创建时间：10:03 2018/8/8

     **/
    public String rightString(StringBuilder str,Integer i){
        int stateIndex=0;//起始坐标
        int endIndex=0;//终止坐标
        int a=i+1;
        //判断是否是负数
        if(str.charAt(i+1)=='-'){
            a=i+2;
        }
        for(int c=a;c<str.length();c++){
            if(str.charAt(c)=='+'||str.charAt(c)=='-'||str.charAt(c)=='*'||str.charAt(c)=='/'||c==str.length()-1){
                if(c==str.length()-1){
                    endIndex=str.length();
                    stateIndex=i+1;
                    break;
                }else{
                    endIndex=c;
                    stateIndex=i+1;
                    break;
                }
            }
        }
        rightIndex=endIndex;
        return str.substring(stateIndex,endIndex);
    }

    /**
     * @创建作者:李然  Lr
     * @方法描述：根据运算符进行运算
     * @创建时间：10:02 2018/8/8

     **/
    public String operationSwitch(String leftParam,String rightParam,char symbol){

        double leftDouble=Double.valueOf(leftParam);
        double rightDouble=Double.valueOf(rightParam);
        double value=0.00;
        switch (symbol){
            case '+': value=leftDouble+rightDouble; break;
            case '-': value=leftDouble-rightDouble; break;
            case '*': value=leftDouble*rightDouble; break;
            case '/': value=leftDouble/rightDouble;break;
        }
        BigDecimal b = new BigDecimal(value);
        double df = b.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
        return df+"";
    }

    /**
     * @创建作者:李然  Lr
     * @方法描述：提取不是数字的字段
     * @创建时间：11:57 2018/8/8

     **/
    public String convertStr(String str1,FlowReport flowReport,Map maps,Integer m){
        StringBuilder str=new StringBuilder(str1);
        int stateStr=0;//字符串起始坐标
        int endStr=0;//字符串终止坐标
        for(int i=0;i<str.length();i++){
            char a=str.charAt(i);
            if(a!='+' && a!='-'&& a!='*' && a!='/' && a!='(' &&a!=')'){
                //获取起始坐标
                stateStr=i;
                for(int j=stateStr;j<str.length();j++){
                    char b=str.charAt(j);
                    if(b=='+' || b=='-'|| b=='*' || b=='/' || b=='(' || b==')'||j==str.length()-1){
                        //获取终止坐标
                        endStr=j;
                        String result=null;
                        if(j==str.length()-1){
                            result=strGoDB(str.substring(stateStr,endStr+1),flowReport,maps,m);
                        }else {
                            result = strGoDB(str.substring(stateStr, endStr),flowReport,maps,m);
                        }
                        if(result!=null&& !result.equals("")&&result.length()>0) {
                            if(result.equals(cuowu)){
                                return null;
                            }
                            if(j==str.length()-1){
                                str=str.replace(stateStr,endStr+1,result);
                            }else{
                                str=str.replace(stateStr,endStr,result);
                            }
                            i=-1;
                            break;
                        }else if(result==null){
                            return null;
                        }
                        else{
                            i=j;
                            break;
                        }
                    }
                }
            }
        }
        return str.toString();
    }

    //判断是否是数字，如果不是数字，而是字段，将其转换为数字
    public String strGoDB(String str,FlowReport flowReport,Map maps,Integer m){
        String result= null;
       try {
            result = "";
            if(str.matches(number)==false){
                if(flowReport!=null) {
                    Document document = getField(flowReport);
                    String data = getCustomData(document, str);
                    if(data!=null){
                        maps.put("data",data);
                        List<String> valueList = flowReportMapper.getValue(maps);
                        if(valueList.get(m).matches(number)==false){
                            return cuowu;
                        }
                        result=valueList.get(m);
                    }else{
                        return null;
                    }
                }

            }
        } catch (Exception e) {
            return null;
        }
        return result;
    }

    public Document getField(FlowReport flowReport){
        Integer formId=flowReport.getFormId();
        Document document=null;
        if(formId!=null){
            FlowFormType flowFormType=flowFormTypeMapper.qureyItemMax(formId);
            //解析html
            document=Jsoup.parse(flowFormType.getPrintModel());
        }

        return document;
    }

    public String getCustomData(Document document,String str){
        Elements elements = document.select("[title="+str+"]");
        String name=null;
        if(elements.size()>0) {
            for (int i = 0; i < elements.size(); i++) {
                name = elements.get(i).attr("name");
            }
        }
        return name;
    }
    public String getCustomTitle(Document document,String str){
        Elements elements = document.select("[name="+str+"]");
        String name=null;
        if(elements.size()>0) {
            for (int i = 0; i < elements.size(); i++) {
                name = elements.get(i).attr("title");
            }
        }
        return name;
    }

    @Override
    public ToJson<FlowReport> updateReportSettings(Integer rId, Integer tid, String flowId, String rName, String[] listItem, String[] queryItem, String createUser, String groupType, String groupField, String formId) {
        ToJson<FlowReport> json = new ToJson<FlowReport>(1, "err");
        try {
            if(tid == null){
                tid = 0;
            }
            List Itemlist = new ArrayList();//listItem字段转化
            List queryItemList = new ArrayList();
            //"{field=DATA_8, disp_name=费用预计, calc_type=0, formulate=, weight=}
            Map<String,Object>itemMap = new HashMap<String,Object>();
            Map<String,Object>queryMap = new HashMap<String,Object>();
            //定义字符串循环遍历数组
            String item = null;
            String query = null;
            //"{field=DATA_8, disp_name:费用预计, calc_type:0, formulate:, weight:}
            if(listItem.length>0){
                for(int i =0;i<listItem.length;i++){
                    if(!"".equals(listItem[i])){
                        String[] itemArray = listItem[i].split(",");
                        for(int j =0;j<itemArray.length;j++){
                            item = itemArray[j];
                            itemMap.put(item.substring(0,item.indexOf("=")), item.substring(item.indexOf("=")+1,item.length()));
                        }
                        Itemlist.add(itemMap);
                        itemMap = new HashMap<>();
                    }

                }
            }
            if(queryItem.length>0){
                for(int i =0;i<queryItem.length;i++){
                    if(!"".equals(queryItem[i])){
                        String[] queryArray = queryItem[i].split(",");
                        for(int j =0;j<queryArray.length;j++){
                            query = queryArray[j];
                            queryMap.put(query.substring(0,query.indexOf("=")), query.substring(query.indexOf("=")+1,query.length()));
                        }
                        queryItemList.add(queryMap);
                        queryMap = new HashMap<>();
                    }
                }
            }
            Date date = new Date();
            SimpleDateFormat aDate=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String createDate = aDate.format(date);
            //序列化与21数据库一样的数据格式
            String ListItemStr = Pherialize.serialize(Itemlist);
            String QueryItemStr = Pherialize.serialize(queryItemList);
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("rId", rId);
            map.put("tId", tid);
            map.put("flowId", flowId);
            map.put("formId", formId);
            map.put("rName", rName);
            map.put("listItem", ListItemStr);
            map.put("queryItem", QueryItemStr);
            map.put("createUser", createUser);
            map.put("createDate",createDate);
            map.put("groupType", groupType);
            map.put("groupField", groupField);
            int count = flowReportMapper.updateReportSettings(map);
            if (count > 0) {
                json.setMsg("ok");
                json.setFlag(0);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    //分组
    public List<List>  grouping(List<FlowReportResult> list,FlowReport flowReport){
        Integer count=0;//每组有几条数据
        //列字段
        List<String> titleList=new ArrayList<>();
        //展示页面数据
        List<FlowReportResult> listMain=new ArrayList<>();
        if(list.size()>0){
            for(int i=0;i<list.size();i++){
                if(list.get(i).getDisp_name()!=null && !list.get(i).getDisp_name().equals("")) {
                    titleList.add(list.get(i).getDisp_name());
                }
            }
            if(flowReport.getGroupType().equals("0") && !"run_id".equals(flowReport.getGroupField())) {
                titleList.add(1, "流程数量");
            }
         /*   for(int i=0;i<list.size();i++){
                if(list.get(i).getRunNameField()!=null && !("").equals(list.get(i).getRunNameField())){
                    titleList.add(2,list.get(i).getRunNameField());
                }
            }*/
            List<String> dispList=new ArrayList<>();
            for(int i=0;i< list.get(0).getList().size();i++){
                if(!list.get(0).getList().get(i).equals("")){
                    dispList.add(list.get(0).getList().get(i));
                }
            }

            for(int i=0;i<dispList.size();i++){
                if(!dispList.get(i).trim().equals("")) {
                    //每一组内的数据
                    List<List> bodyList=new ArrayList<>();
                    FlowReportResult flowReportResult=new FlowReportResult();
                    for(int j=0;j<list.get(0).getList().size();j++){
                        if (dispList.get(i).equals(list.get(0).getList().get(j))) {
                            flowReportResult.setDisp_name(dispList.get(i));
                            //每一组每一行
                            List<String> dispLine=new ArrayList<>();

                            for(int a=1;a<list.size();a++){
                                //获取每一列的指定数据
                                if(list.get(a).getList().size()>0) {
                                    dispLine.add(list.get(a).getList().get(j));
                                }
                            }
                            Integer isNull=0;

                            boolean isInsert=true;
                            //判断最后一行
                            if(i<dispList.size()-1){
                                if(dispLine.size()>0) {
                                    for (int c=0;c<dispLine.size();c++) {
                                        if(dispLine.get(i).trim().equals("")){
                                            isNull++;
                                        }else{
                                            break;
                                        }
                                    }
                                    if(isNull==dispLine.size()){
                                        isInsert=false;
                                    }else{
                                        isInsert=true;
                                    }
                                }
                            }

                            //如果每一组的每一行有数据
                            if(isInsert==true){
                                bodyList.add(dispLine);
                            }
                        }
                    }
                    if(bodyList.size()>0) {
                        if (flowReport.getGroupType().equals("0") && !"run_id".equals(flowReport.getGroupField())) {
                            flowReportResult.setDispCount(bodyList.size());
                            count = count + bodyList.size();
                        }
                        flowReportResult.setDispList(bodyList);
                        listMain.add(flowReportResult);
                    }
                    List dispListR=new ArrayList();
                    for(int c=0;c<dispList.size();c++) {
                        if(!dispList.get(c).equals(dispList.get(i))) {
                            dispListR.add(dispList.get(c));
                        }
                    }
                    dispList=dispListR;
                    i=-1;
                    if(dispList==null||dispList.size()<=0){
                        if(flowReport.getGroupType().equals("0") && !"run_id".equals(flowReport.getGroupField())) {
                            if(listMain.size()>0) {
                                listMain.get(listMain.size() - 1).setDispCount(count - 1);
                            }
                        }
                        break;
                    }
                }
            }
        }
        List<List> mainList=new ArrayList<>();
        mainList.add(titleList);
        mainList.add(listMain);
        return mainList;
    }
    /**
    * @创建作者:李然  Lr
    * @方法描述：转大写
    * @创建时间：14:11 2018/8/30

    **/
    private String ConvertMoneyBig(Double lower){
        String bigNum = null;
        try {
            BigDecimal numberOfMoney = new BigDecimal(lower);
            bigNum = ConvertMoney.number2CNMontrayUnit(numberOfMoney);
        } catch (Exception e) {
            return null;
        }
        return bigNum;
    }
    /**
    * @创建作者:李然  Lr
    * @方法描述：大写转小写
    * @创建时间：14:16 2018/8/30

    **/
    private Double ConvertMoneyLower(String big){
        Double lowerNum= null;
        try {
            lowerNum = ConvertMoney.ComputeResult(big);
        } catch (Exception e) {
            return null;
       }
       if(lowerNum==0.0){
            return null;
       }
        return lowerNum;
    }
}